package com.struts.deal.user.register;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.upload.FormFile;
import com.lg.system.*;
import com.base.BaseAction;
import com.base.BaseLog;
import com.ibatis.po.user.*;
import com.ibatis.po.system.*;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.lg.system.CSqlMap;
import com.struts.web.user.register.*;
import java.util.*;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class Deal extends BaseAction{

	/**
	 * 增加用户的基本信息
	 * @param request
	 * @param aWebForm
	 * @return
	 * @throws SQLException
	 */
	public static boolean doBaseInfo(HttpServletRequest request,BaseInfoForm aWebForm) throws SQLException {
		boolean result = false;
		TUser user =  new TUser();
		Date birth =null;
		if(aWebForm.getBirthday()!=null && aWebForm.getBirthday().length()>0 ){
			birth = Date.valueOf(aWebForm.getBirthday());//
		}
		String othersnation = "";
		String nation = aWebForm.getNation();
		if(aWebForm.getNation() !=null && aWebForm.getNation().equals("1") && aWebForm.getOthersnation()!=null && aWebForm.getOthersnation().length()>0){
			othersnation=aWebForm.getOthersnation();
		}
		user.setId(Common.getNewID());
		user.setLoginname(aWebForm.getLoginName());
		user.setPassword(aWebForm.getPassword());
		user.setName(aWebForm.getName());
		user.setSex(aWebForm.getSex());
		user.setNation(nation);
		user.setOthersnation(othersnation);
		user.setBirthday(birth);
		user.setIdcard(aWebForm.getIdcard());
		user.setStature(aWebForm.getStature());
		user.setMarriagestatus(aWebForm.getMarriageStatus());
		user.setRegisteredaddress(aWebForm.getRegisteredAddress());
		user.setNowaddress(aWebForm.getNowAddress());
		user.setEducational(aWebForm.getEducation());
		user.setWorkexperience(aWebForm.getWorkExperience());
		user.setZyzc(aWebForm.getZyzc());
		user.setTelephone(aWebForm.getTelephone());
		user.setMobilephone(aWebForm.getMobilephone());
		user.setQq(aWebForm.getQq());
		user.setMsn(aWebForm.getMsn());
		user.setEmail(aWebForm.getEmail());
		user.setHomepage(aWebForm.getHomepage());
		user.setComunicationaddress(aWebForm.getComunicationAddress());
		user.setPostalcode(aWebForm.getPostalcode());
		user.setCreatetime(new Timestamp(new java.util.Date().getTime()));
		user.setLastmodifytime(new Timestamp(new java.util.Date().getTime()));
		user.setLastlogin(new Timestamp(new java.util.Date().getTime()));

		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		try{
			if(user.getLoginname()!=null && user.getLoginname().length()>0){
				int count = 0;
				count=((Integer)sqlmap.queryForObject("T_USER.selectCountByLoginName", user)).intValue();
				if(user.getPassword()!=null && user.getPassword().length()>0 && count<1){	
					sqlmap.insert("T_USER.abatorgenerated_updateByPrimaryKeySelective", user);
					request.getSession().setAttribute("TUser", user);
					result = true;
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;

	}


	/**
	 *�
	 */
	public static void doEducation(HttpServletRequest request,EducationTrainForm aWebForm) throws SQLException {
		TEducation tEducation1 = new TEducation();
		TEducation tEducation2 = new TEducation();
		TEducation tEducation3 = new TEducation();

		TTrainExperience train1 = new TTrainExperience();
		TTrainExperience train2 = new TTrainExperience();
		TTrainExperience train3 = new TTrainExperience();

		TUserSkill  userSkill = new TUserSkill();
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		try{
			TUser user = (TUser)request.getSession().getAttribute("TUser");
			String userid = user.getId();
			if(aWebForm.getStartYear1()!=null && aWebForm.getStartYear1().length()>0){
				tEducation1.setId(Common.getNewID());
				tEducation1.setUserid(userid);
				tEducation1.setStartYear(aWebForm.getStartYear1());
				tEducation1.setStartMonth(aWebForm.getStartMonth1());
				tEducation1.setEndYear(aWebForm.getEndYear1());
				tEducation1.setEndMonth(aWebForm.getEndMonth1());
				tEducation1.setSchoolName(aWebForm.getSchoolName1());
				tEducation1.setSpeciality(aWebForm.getSpeciality1());
				tEducation1.setDescriptionEducation(aWebForm.getDescriptionEducation1());
				tEducation1.setXueLi(aWebForm.getXueLi1());
				tEducation1.setOrderNum("1");
				saveEducation(tEducation1);

				if(aWebForm.getStartYear2()!=null && aWebForm.getStartYear2().length()>0){
					tEducation2.setId(Common.getNewID());
					tEducation2.setUserid(userid);
					tEducation2.setStartYear(aWebForm.getStartYear2());
					tEducation2.setStartMonth(aWebForm.getStartMonth2());
					tEducation2.setEndYear(aWebForm.getEndYear2());
					tEducation2.setEndMonth(aWebForm.getEndMonth2());
					tEducation2.setSchoolName(aWebForm.getSchoolName2());
					tEducation2.setSpeciality(aWebForm.getSpeciality2());
					tEducation2.setDescriptionEducation(aWebForm.getDescriptionEducation2());
					tEducation2.setXueLi(aWebForm.getXueLi2());
					tEducation2.setOrderNum("2");
					saveEducation(tEducation2);
				}

				if(aWebForm.getStartYear3()!=null && aWebForm.getStartYear3().length()>0){
					tEducation3.setId(Common.getNewID());
					tEducation3.setUserid(userid);
					tEducation3.setStartYear(aWebForm.getStartYear3());
					tEducation3.setStartMonth(aWebForm.getStartMonth3());
					tEducation3.setEndYear(aWebForm.getEndYear3());
					tEducation3.setEndMonth(aWebForm.getEndMonth1());
					tEducation3.setSchoolName(aWebForm.getSchoolName3());
					tEducation3.setSpeciality(aWebForm.getSpeciality3());
					tEducation3.setDescriptionEducation(aWebForm.getDescriptionEducation3());
					tEducation3.setXueLi(aWebForm.getXueLi3());
					tEducation3.setOrderNum("3");
					saveEducation(tEducation3);
				}
			}



			if(aWebForm.getTstartYear1()!=null && aWebForm.getTstartYear1().length()>0){
				train1.setId(Common.getNewID());
				train1.setUserid(userid);
				train1.setTrainOrganization(aWebForm.getTtrainOrganize1());
				train1.setTrainCourse(aWebForm.getTtrainCource1());
				train1.setCertificate(aWebForm.getTcertificate1());
				train1.setStartYear(aWebForm.getTstartYear1());
				train1.setStartMonth(aWebForm.getTstartMonth1());
				train1.setEndYear(aWebForm.getTendYear1());
				train1.setEndMonth(aWebForm.getTendMonth1());
				train1.setOrderNum("1");
				saveTrain(train1);//更新或插入

				if(aWebForm.getTstartYear2()!=null && aWebForm.getTstartYear2().length()>0){
					train2.setId(Common.getNewID());
					train2.setUserid(userid);
					train2.setTrainOrganization(aWebForm.getTtrainOrganize2());
					train2.setTrainCourse(aWebForm.getTtrainCource2());
					train2.setCertificate(aWebForm.getTcertificate2());
					train2.setStartYear(aWebForm.getTstartYear2());
					train2.setStartMonth(aWebForm.getTstartMonth2());
					train2.setEndYear(aWebForm.getTendYear2());
					train2.setEndMonth(aWebForm.getTendMonth2());
					train2.setOrderNum("2");
					saveTrain(train2);//更新或插入
				}

				if(aWebForm.getTstartYear3()!=null && aWebForm.getTstartYear3().length()>0){
					train3.setId(Common.getNewID());
					train3.setUserid(userid);
					train3.setTrainOrganization(aWebForm.getTtrainOrganize3());
					train3.setTrainCourse(aWebForm.getTtrainCource3());
					train3.setCertificate(aWebForm.getTcertificate3());
					train3.setStartYear(aWebForm.getTstartYear3());
					train3.setStartMonth(aWebForm.getTstartMonth3());
					train3.setEndYear(aWebForm.getTendYear3());
					train3.setEndMonth(aWebForm.getTendMonth3());
					train3.setOrderNum("3");
					saveTrain(train3);//更新或插入
				}
			}



			int count = 0;
			userSkill.setId(Common.getNewID());
			userSkill.setUserid(userid);
			userSkill.setMandarin(aWebForm.getMandarin());
			userSkill.setCantonese(aWebForm.getCantonese());
			userSkill.setEnglish(aWebForm.getEnglish());
			userSkill.setEnglishLevel(aWebForm.getEnglishLevel());
			userSkill.setOtherLanguage(aWebForm.getOtherLanguage());
			userSkill.setSkillDescription(aWebForm.getSkillDescription());
			userSkill.setComputer(aWebForm.getComputer());
			userSkill.setOtherLanguageLevel(aWebForm.getOtherLanguageLevel());
			count = (Integer) sqlmap.queryForObject("T_USER_SKILL.selectByUserId",userSkill);
			if(count>0){
				sqlmap.update("T_USER_SKILL.updateByUserId",userSkill);
			}else{
				sqlmap.insert("T_USER_SKILL.abatorgenerated_insert", userSkill); 
			}
		}catch(Exception e){
			e.printStackTrace();
		}

	}

	/**
	 *��
	 */
	public static void doSociatyExperience(HttpServletRequest request,SocietyExperienceForm aWebForm) throws SQLException {

		TUser user = (TUser)request.getSession().getAttribute("TUser");
		String userid = user.getId();
		TWorkExperience sociatyExperience1 =  new TWorkExperience();
		TWorkExperience sociatyExperience2 =  new TWorkExperience();
		TWorkExperience sociatyExperience3 =  new TWorkExperience();
		TWorkExperience sociatyExperience4 =  new TWorkExperience();
		TWorkExperience sociatyExperience5 =  new TWorkExperience();



		sociatyExperience1.setId(Common.getNewID());
		sociatyExperience1.setUserid(userid);
		sociatyExperience1.setCorporationName(aWebForm.getSocietyExperienceBean1().getCorporationName());
		sociatyExperience1.setEndMonth(aWebForm.getSocietyExperienceBean1().getEndMonth());
		sociatyExperience1.setEndYear(aWebForm.getSocietyExperienceBean1().getEndYear());
		sociatyExperience1.setStartMonth(aWebForm.getSocietyExperienceBean1().getStartMonth());
		sociatyExperience1.setStartYear(aWebForm.getSocietyExperienceBean1().getStartYear());
		sociatyExperience1.setPostName(aWebForm.getSocietyExperienceBean1().getPositionName());
		sociatyExperience1.setWorkStatus(aWebForm.getSocietyExperienceBean1().getWorkStatus());
		sociatyExperience1.setWorkDescription(aWebForm.getSocietyExperienceBean1().getWorkStatus());
		sociatyExperience1.setSecrecy(aWebForm.getSocietyExperienceBean1().getSecrete());
		sociatyExperience1.setMonthlyPay(aWebForm.getSocietyExperienceBean1().getMonthlyPay());

		sociatyExperience2.setId(Common.getNewID());
		sociatyExperience2.setUserid(userid);
		sociatyExperience2.setCorporationName(aWebForm.getSocietyExperienceBean2().getCorporationName());
		sociatyExperience2.setEndMonth(aWebForm.getSocietyExperienceBean2().getEndMonth());
		sociatyExperience2.setEndYear(aWebForm.getSocietyExperienceBean2().getEndYear());
		sociatyExperience2.setStartMonth(aWebForm.getSocietyExperienceBean2().getStartMonth());
		sociatyExperience2.setStartYear(aWebForm.getSocietyExperienceBean2().getStartYear());
		sociatyExperience2.setPostName(aWebForm.getSocietyExperienceBean2().getPositionName());
		sociatyExperience2.setWorkStatus(aWebForm.getSocietyExperienceBean2().getWorkStatus());
		sociatyExperience2.setWorkDescription(aWebForm.getSocietyExperienceBean2().getWorkStatus());
		sociatyExperience2.setSecrecy(aWebForm.getSocietyExperienceBean2().getSecrete());
		sociatyExperience2.setMonthlyPay(aWebForm.getSocietyExperienceBean2().getMonthlyPay());

		sociatyExperience3.setId(Common.getNewID());
		sociatyExperience3.setUserid(userid);
		sociatyExperience3.setCorporationName(aWebForm.getSocietyExperienceBean3().getCorporationName());
		sociatyExperience3.setEndMonth(aWebForm.getSocietyExperienceBean3().getEndMonth());
		sociatyExperience3.setEndYear(aWebForm.getSocietyExperienceBean3().getEndYear());
		sociatyExperience3.setStartMonth(aWebForm.getSocietyExperienceBean3().getStartMonth());
		sociatyExperience3.setStartYear(aWebForm.getSocietyExperienceBean3().getStartYear());
		sociatyExperience3.setPostName(aWebForm.getSocietyExperienceBean3().getPositionName());
		sociatyExperience3.setWorkStatus(aWebForm.getSocietyExperienceBean3().getWorkStatus());
		sociatyExperience3.setWorkDescription(aWebForm.getSocietyExperienceBean3().getWorkStatus());
		sociatyExperience3.setSecrecy(aWebForm.getSocietyExperienceBean3().getSecrete());
		sociatyExperience3.setMonthlyPay(aWebForm.getSocietyExperienceBean3().getMonthlyPay());

		sociatyExperience4.setId(Common.getNewID());
		sociatyExperience4.setUserid(userid);
		sociatyExperience4.setCorporationName(aWebForm.getSocietyExperienceBean4().getCorporationName());
		sociatyExperience4.setEndMonth(aWebForm.getSocietyExperienceBean4().getEndMonth());
		sociatyExperience4.setEndYear(aWebForm.getSocietyExperienceBean4().getEndYear());
		sociatyExperience4.setStartMonth(aWebForm.getSocietyExperienceBean4().getStartMonth());
		sociatyExperience4.setStartYear(aWebForm.getSocietyExperienceBean4().getStartYear());
		sociatyExperience4.setPostName(aWebForm.getSocietyExperienceBean4().getPositionName());
		sociatyExperience4.setWorkStatus(aWebForm.getSocietyExperienceBean4().getWorkStatus());
		sociatyExperience4.setWorkDescription(aWebForm.getSocietyExperienceBean4().getWorkStatus());
		sociatyExperience4.setSecrecy(aWebForm.getSocietyExperienceBean4().getSecrete());
		sociatyExperience4.setMonthlyPay(aWebForm.getSocietyExperienceBean4().getMonthlyPay());

		sociatyExperience5.setId(Common.getNewID());
		sociatyExperience5.setUserid(userid);
		sociatyExperience5.setCorporationName(aWebForm.getSocietyExperienceBean5().getCorporationName());
		sociatyExperience5.setEndMonth(aWebForm.getSocietyExperienceBean5().getEndMonth());
		sociatyExperience5.setEndYear(aWebForm.getSocietyExperienceBean5().getEndYear());
		sociatyExperience5.setStartMonth(aWebForm.getSocietyExperienceBean5().getStartMonth());
		sociatyExperience5.setStartYear(aWebForm.getSocietyExperienceBean5().getStartYear());
		sociatyExperience5.setPostName(aWebForm.getSocietyExperienceBean5().getPositionName());
		sociatyExperience5.setWorkStatus(aWebForm.getSocietyExperienceBean5().getWorkStatus());
		sociatyExperience5.setWorkDescription(aWebForm.getSocietyExperienceBean5().getWorkStatus());
		sociatyExperience5.setSecrecy(aWebForm.getSocietyExperienceBean5().getSecrete());
		sociatyExperience5.setMonthlyPay(aWebForm.getSocietyExperienceBean5().getMonthlyPay());

		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		try{
			sqlmap.insert("T_WORK_EXPERIENCE.abatorgenerated_insert", sociatyExperience1);
			sqlmap.insert("T_WORK_EXPERIENCE.abatorgenerated_insert", sociatyExperience2);
			sqlmap.insert("T_WORK_EXPERIENCE.abatorgenerated_insert", sociatyExperience3);
			sqlmap.insert("T_WORK_EXPERIENCE.abatorgenerated_insert", sociatyExperience4);
			sqlmap.insert("T_WORK_EXPERIENCE.abatorgenerated_insert", sociatyExperience5);

			if(aWebForm.getDescriptForJob()!=null && aWebForm.getDescriptForJob().length()>0){
				user.setDescriptionforjob(aWebForm.getDescriptForJob());
				sqlmap.update("T_USER.updateDescriptWork", user);
			}
		}catch(Exception e){
			e.printStackTrace();
		}

	}



	/**
	 * ��
	 */
	public static void doPicture(HttpServletRequest request,UserPictureForm aWebForm) throws SQLException {
		TUser user = (TUser)request.getSession().getAttribute("TUser");
		String userid = user.getId();
		TImages images = new TImages();

		String dir = request.getRealPath("/userpicture");
		String filename = null;
		FormFile file = aWebForm.getPicture();
		InputStream in = null;
		OutputStream out = null;

		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		try{

			filename = file.getContentType();
			if (file==null||filename.length()<1){
			}else{				
				in = file.getInputStream();
				if(file.getContentType().equals("imag/pjpeg")){
					out = new FileOutputStream(dir+"/"+userid+".jpg");
					filename = userid+".jpg";
				}else{
					out = new FileOutputStream(dir+"/"+userid+".gif");
					filename = userid+".gif";
				}
				int readed = 0;
				byte[] buffer= new byte[1024];
				while ((readed=in.read(buffer,0,1024))!=-1){
					out.write(buffer,0,readed);
				}
				images.setId(userid);
				images.setUserId(userid);
				images.setImageUrl("/userpicture/"+filename);
				images.setImageStatus("0");
	
				sqlmap.insert("T_IMAGES.abatorgenerated_insert", images);
			}

		}catch(Exception e){
			e.printStackTrace();
		}

	}

	public static void setDefault(
			HttpServletRequest request,
			HttpServletResponse response,
			BaseInfoForm aWebForm){
		List cityList=null;
		TCiyt cityPo = new TCiyt();
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		try{
			cityList = sqlmap.queryForList("T_CIYT.selectAllCity");
			String str="";
			String str2="";
			String sKey="";
			String sValue="";

			str += "var regAddress=new Array('','－－请选择所在地－－'";
			str2 += "var nowAddr=new Array('','－－请选择所在地－－'";
			//户口所在地列表
			for(int i=0;i<cityList.size();i++){
				cityPo = (TCiyt)cityList.get(i);
				sKey = cityPo.getId();
				sValue = cityPo.getCityName();
				if((Integer.parseInt(sKey)%100)==0){
					str += ",'" + sKey + "',"; //取出的TREEMAP的KEY
					str2+= ",'" + sKey + "',";
					str += "'" + sValue + "'\n"; //取出的TREEMAP的value
					str2 += "'" + sValue + "'\n";
				}else{
					str += ",'" + sKey + "',"; //取出的TREEMAP的KEY
					str2 += ",'" + sKey + "',";
					str += "'&nbsp;&nbsp;&nbsp;&nbsp;" + sValue + "'\n"; //取出的TREEMAP的value
					str2 += "'&nbsp;&nbsp;&nbsp;&nbsp;" + sValue + "'\n";
				}
			}
			str += ");\n";
			str2 += ");\n";
			//把部门数组输出到页面上
			aWebForm.setPrintRegSql(str);
			aWebForm.setPrintNowSql(str2);
		}catch(Exception e){
			e.printStackTrace();
		}

	}

	//对社会经历表进行操作
	public static  void  saveTrain(TTrainExperience train) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		int count= 0;
		try{
			count = ((Integer)sqlmap.queryForObject("T_TRAIN_EXPERIENCE.selectByUseridOrer", train)).intValue();
			if(count>0){
				sqlmap.update("T_TRAIN_EXPERIENCE.updateByUserId", train);
			}else{
				sqlmap.insert("T_TRAIN_EXPERIENCE.abatorgenerated_insert", train);
			}
		}catch(Exception e){
			e.printStackTrace();
		}

	}

	/**
	 * 对教育表进行操作
	 * @param train
	 * @throws SQLException
	 */
	public static  void  saveEducation(TEducation education) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		int count= 0;
		try{
			count = ((Integer)sqlmap.queryForObject("T_EDUCATION.selectByUseridOrder", education)).intValue();
			if(count>0){
				sqlmap.update("T_EDUCATION.updateByUseridOrder", education);
			}else{
				sqlmap.insert("T_EDUCATION.abatorgenerated_insert", education);
			}
		}catch(Exception e){
			e.printStackTrace();
		}

	}

	/**
	 * 注册用户登录信息
	 * @param education
	 * @throws SQLException
	 */
	public static  boolean  doRegLogin(RegLoginForm aWebForm,HttpServletRequest request) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TUserInfo user = new TUserInfo();
		boolean result = false;
		try{
			user.setId(Common.getNewID());
			user.setLoginName(aWebForm.getLoginName());
			user.setPassword(aWebForm.getPassword());
			user.setEmail(aWebForm.getEmail());
			user.setQuestion(aWebForm.getQuestion());
			user.setAnswer(aWebForm.getAnswer());
			if(user.getLoginName()!=null && user.getLoginName().length()>0){
				int count = 0;
				count=((Integer)sqlmap.queryForObject("T_USER_INFO.selectIsExist", user.getLoginName())).intValue();
				if(user.getPassword()!=null && user.getPassword().length()>0 && count<1){
					sqlmap.insert("T_USER_INFO.insertLogin", user);
					request.getSession().setAttribute("TUser", user);
					result = true;
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}

	public static  void  doDefault(RegUserInfoForm aWebForm,HttpServletRequest request) throws SQLException{
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		List stationList = null;
		String str2="";
		String sKey="";
		List substationList = null;
		TStation  station = new TStation();
		try{
			str2 += "var station=new Array('','－－请选择－－'";
			stationList = sqlmap.queryForList("T_STATION.selectAllSubNotNull");
        	int length  = stationList.size();
        	for(int i=0;i<stationList.size();i++){
        		station=(TStation)stationList.get(i);
        		str2+=",'"+station.getId()+"',";
        		str2+="'"+station.getSortName()+"'\n";
        	}
        	str2+=");\n";
        	if(length>0){
            	str2+="var substation=new Array("+length+");\n";
            	str2+="substation[0]=new Array('','');\n";
            	for(int i=0;i<stationList.size();i++){
            	station=(TStation)stationList.get(i);
            	sKey = station.getId();
            	TSubStation substationPo = new TSubStation();
            	String sortId = sKey;
            	substationList = sqlmap.queryForList("T_SUB_STATION.selectBySortId",sortId);
            	if(substationList.size()>0){
            		substationPo = (TSubStation)substationList.get(0);
            	
            	str2+="substation["+(i+1)+"]=new Array('"+substationPo.getId()+"','"+substationPo.getPostName()+"'\n";  
            	}
            	  for(int j=1;j<substationList.size();j++){
            		  substationPo=(TSubStation)substationList.get(j);
            		  str2+=",'"+substationPo.getId()+"','"+substationPo.getPostName()+"'\n";
            	  }
            	  str2+=");\n";
            	}
            	}
        	aWebForm.setPrintStaSql(str2);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 注册用户信息
	 * @param aWebForm
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public static  boolean  doUserInfo(RegUserInfoForm aWebForm,HttpServletRequest request) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		boolean result = false;
		TUserInfo user = (TUserInfo)request.getSession().getAttribute("TUser");
		String userid = user.getId();
		try{
			if(user!=null){
				user.setName(aWebForm.getName());
				user.setSex(aWebForm.getSex());
				user.setBirthday(Date.valueOf(aWebForm.getBirthday()));
				user.setEducation(aWebForm.getEducation());
				user.setSchoolName(aWebForm.getSchoolName());
				user.setSpeciality(aWebForm.getSpeciality());
				user.setMobilphone(aWebForm.getMobilphone());
				user.setTelephone(aWebForm.getTelephone());
				user.setNowAddress(aWebForm.getNowAddress());
				user.setNowPostalCode(aWebForm.getNowPostalCode());
				user.setRegisteredAddress(aWebForm.getRegisteredAddress());
				user.setRegPostalCode(aWebForm.getRegPostalCode());
				
				user.setFavoriteJob(aWebForm.getStationTextList());

				if(aWebForm.getEducationBgDate1()!=null && aWebForm.getEducationBgDate1()!="" && aWebForm.getEducationBgDate12()!=null && aWebForm.getEducationBgDate12()!=""){
					user.setEducationBgDate1(aWebForm.getEducationBgDate1()+"至"+aWebForm.getEducationBgDate12());
				}
				if(aWebForm.getEducationBgDate2()!=null && aWebForm.getEducationBgDate2()!="" && aWebForm.getEducationBgDate22()!=null && aWebForm.getEducationBgDate22()!=""){
					user.setEducationBgDate2(aWebForm.getEducationBgDate2()+"至"+aWebForm.getEducationBgDate22());
				}
				if(aWebForm.getEducationBgDate3()!=null && aWebForm.getEducationBgDate3()!="" && aWebForm.getEducationBgDate32()!=null &&aWebForm.getEducationBgDate32()!=""){
					user.setEducationBgDate3(aWebForm.getEducationBgDate3()+"至"+aWebForm.getEducationBgDate32());
				}
				user.setEducationBg1(aWebForm.getEducationBg1());
				user.setEducationBg2(aWebForm.getEducationBg2());
				user.setEducationBg3(aWebForm.getEducationBg3());
				user.setEnglish(aWebForm.getEnglish());
				user.setSpecialityLevel(aWebForm.getSpecialityLevel());

				if(aWebForm.getSocialityDate1()!=null && aWebForm.getSocialityDate1()!="" && aWebForm.getSocialityDate12()!=null && aWebForm.getSocialityDate12()!=""){
					user.setSocialityDate1(aWebForm.getSocialityDate1()+"至"+aWebForm.getSocialityDate12());
				}
				if(aWebForm.getSocialityDate2()!=null && aWebForm.getSocialityDate2()!="" && aWebForm.getSocialityDate22()!=null && aWebForm.getSocialityDate22()!=""){
					user.setSocialityDate2(aWebForm.getSocialityDate2()+"至"+aWebForm.getSocialityDate22());
				}
				if(aWebForm.getSocialityDate3()!=null && aWebForm.getSocialityDate3()!="" && aWebForm.getSocialityDate32()!=null && aWebForm.getSocialityDate32()!=""){
					user.setSocialityDate3(aWebForm.getSocialityDate3()+"至"+aWebForm.getSocialityDate32());
				}
				user.setSociality1(aWebForm.getSociality1());
				user.setSociality2(aWebForm.getSociality2());
				user.setSociality3(aWebForm.getSociality3());
				user.setCourse(aWebForm.getCourse());
				user.setDescriptYourself(aWebForm.getDescriptYourself());
				user.setFeatures(aWebForm.getFeatures());
				sqlmap.update("T_USER_INFO.abatorgenerated_updateByPrimaryKeySelective", user);
                //意向岗位
	        	if(aWebForm.getStationList()!=null && aWebForm.getStationList().length()>0){
	        		TFavoritePost  fpositionPo = new TFavoritePost();
	    			String[]  fpositionArray = aWebForm.getStationList().split(",");
	    			fpositionPo.setUserid(userid);
	    			sqlmap.delete("T_FAVORITE_POST.deleteByUserId",fpositionPo);
	    			for(int i=0;i<fpositionArray.length;i++){
	    				fpositionPo.setId(Common.getNewID());
	    				fpositionPo.setUserid(userid);
	    				fpositionPo.setPostId(fpositionArray[i]);
	    				System.out.println("sssssssssssssssss:"+fpositionArray[i]);
	    				sqlmap.insert("T_FAVORITE_POST.abatorgenerated_insert",fpositionPo);
	    			}
	    			
	    		}
				request.getSession().setAttribute("TUser", user);
				result = true;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 加载用户信息
	 * @param aWebForm
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public static  void  defaultUserInfo(RegUserInfoForm aWebForm,HttpServletRequest request) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TUserInfo user = (TUserInfo)request.getSession().getAttribute("TUser");
		String userId = user.getId();
		String str3="";
    	String str4="";
    	List stationList = null;
    	List substationList = null;
		TStation  station = new TStation();
		List favoriteList = null;
		String sKey="";
        String sValue="";
		try{
			if(user!=null){
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
				TUserInfo user1 = (TUserInfo)sqlmap.queryForObject("T_USER_INFO.abatorgenerated_selectByPrimaryKey",user);
				aWebForm.setName(user1.getName());
				aWebForm.setSex(user1.getSex());
				if(user1.getBirthday()!=null){
					aWebForm.setBirthday(format.format(user1.getBirthday()));
				}else{
					aWebForm.setBirthday("");
				}
                
//				意向行业
	              str3 += "var station=new Array('','－－请选择－－'";
	  			stationList = sqlmap.queryForList("T_STATION.selectAllSubNotNull");
	          	int length  = stationList.size();
	          	for(int i=0;i<stationList.size();i++){
	          		station=(TStation)stationList.get(i);
	          		str3+=",'"+station.getId()+"',";
	          		str3+="'"+station.getSortName()+"'\n";
	          	}
	          	str3+=");\n";
	          	if(length>0){
	              	str3+="var substation=new Array("+length+");\n";
	              	str3+="substation[0]=new Array('','');\n";
	              	for(int i=0;i<stationList.size();i++){
	              	station=(TStation)stationList.get(i);
	              	sKey = station.getId();
	              	TSubStation substationPo = new TSubStation();
	              	String sortId = sKey;
	              	substationList = sqlmap.queryForList("T_SUB_STATION.selectBySortId",sortId);
	              	if(substationList.size()>0){
	              		substationPo = (TSubStation)substationList.get(0);
	              	
	              	str3+="substation["+(i+1)+"]=new Array('"+substationPo.getId()+"','"+substationPo.getPostName()+"'\n";  
	              	}
	              	  for(int j=1;j<substationList.size();j++){
	              		  substationPo=(TSubStation)substationList.get(j);
	              		  str3+=",'"+substationPo.getId()+"','"+substationPo.getPostName()+"'\n";
	              	  }
	              	  str3+=");\n";
	              	}
	              	}
	          	//根据用户id找到意向行业
	          	favoriteList = sqlmap.queryForList("T_FAVORITE_POST.getStationByUserId",userId);
	          	str4 = "var favoriteList = new Array(";
	          	for(int i=0;i<favoriteList.size();i++){
	          		TFavoritePost favoritePo = (TFavoritePost)favoriteList.get(i);
	          		sKey = favoritePo.getPostId();
	          		sValue = favoritePo.getPostName();
	          		if(i==0){
	          		str4 += "'"+sKey+"',";
	          		str4 += "'"+sValue+"'";
	          		}else{
	          			str4 += ",'"+sKey+"',";
	              		str4 += "'"+sValue+"'\n";
	          		}
	          	}
	          	str4 += ");\n";
	          	str3 += str4;
	          	aWebForm.setPrintStaSql(str3);
	          	
				aWebForm.setEducation(user1.getEducation());
				aWebForm.setSchoolName(user1.getSchoolName());
				aWebForm.setSpeciality(user1.getSpeciality());
				aWebForm.setMobilphone(user1.getMobilphone());
				aWebForm.setTelephone(user1.getTelephone());
				aWebForm.setNowAddress(user1.getNowAddress());
				aWebForm.setNowPostalCode(user1.getNowPostalCode());
				aWebForm.setRegisteredAddress(user1.getRegisteredAddress());
				aWebForm.setRegPostalCode(user1.getRegPostalCode());
				
				aWebForm.setFavoriteJob(user1.getFavoriteJob());


				if(user1.getEducationBgDate1()!=null && user1.getEducationBgDate1()!=""){
					String[] ebd1 = user1.getEducationBgDate1().split("至");
					System.out.println("dsddddd:"+ebd1.length);
					if(ebd1.length>0){
						aWebForm.setEducationBgDate1(ebd1[0]);
						aWebForm.setEducationBgDate12(ebd1[1]);
					}
				}


				if(user1.getEducationBgDate2()!=null && user1.getEducationBgDate2()!=""){
					String[] ebd2 = user1.getEducationBgDate2().split("至");
					if(ebd2.length>0){
						aWebForm.setEducationBgDate2(ebd2[0]);
						aWebForm.setEducationBgDate22(ebd2[1]);
					}
				}


				if(user1.getEducationBgDate3()!=null && user1.getEducationBgDate3()!=""){
					String[] ebd3 = user1.getEducationBgDate3().split("至");
					if(ebd3.length>0){
						aWebForm.setEducationBgDate3(ebd3[0]);
						aWebForm.setEducationBgDate32(ebd3[1]);
					}
				}


				aWebForm.setEducationBg1(user1.getEducationBg1());
				aWebForm.setEducationBg2(user1.getEducationBg2());
				aWebForm.setEducationBg3(user1.getEducationBg3());
				aWebForm.setEnglish(user1.getEnglish());
				aWebForm.setSpecialityLevel(user1.getSpecialityLevel());

				if(user1.getSocialityDate1()!=null && user1.getSocialityDate1()!=""){
					String[] sd1 = user1.getSocialityDate1().split("至");
					if(sd1.length>0){
						System.out.println("dddddddddddddddddddd:"+sd1[1]);
						aWebForm.setSocialityDate1(sd1[0]);
						aWebForm.setSocialityDate12(sd1[1]);
					}
				}
				if(user1.getSocialityDate2()!=null && user1.getSocialityDate2()!=""){
					String[] sd2 = user1.getSocialityDate2().split("至");
					if(sd2.length>0){
						aWebForm.setSocialityDate2(sd2[0]);
						aWebForm.setSocialityDate22(sd2[1]);
					}
				}
				if(user1.getSocialityDate3()!=null && user1.getSocialityDate3()!=""){
					String[] sd3 = user1.getSocialityDate3().split("至");
					if(sd3.length>0){

						aWebForm.setSocialityDate3(sd3[0]);
						aWebForm.setSocialityDate32(sd3[1]);
					}
				}
				aWebForm.setSocialityDate2(user1.getSocialityDate2());
				aWebForm.setSocialityDate3(user1.getSocialityDate3());
				aWebForm.setSociality1(user1.getSociality1());
				aWebForm.setSociality2(user1.getSociality2());
				aWebForm.setSociality3(user1.getSociality3());
				aWebForm.setCourse(user1.getCourse());
				aWebForm.setDescriptYourself(user1.getDescriptYourself());
				aWebForm.setFeatures(user1.getFeatures());
				aWebForm.setEmail(user1.getEmail());
				aWebForm.setRegAddrPro(user1.getRegAddrPro());
				aWebForm.setRegAddrCity(user1.getRegAddrCity());
				System.out.println(user1.getRegAddrCity());
				

				if(user1.getImageURL() != null){
					aWebForm.setImageURL("/userpicture/"+user1.getImageURL());
				}else{
					aWebForm.setImageURL("/userpicture/nopicture.gif");
				}

			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}


	/**
	 * 加载用户信息
	 * @param aWebForm
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public static  void  defaultUserSelft(RegUserInfoForm aWebForm,HttpServletRequest request) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TUserInfo user = (TUserInfo)request.getSession().getAttribute("TUser");
		TUserInfo user2 = new TUserInfo();
		try{
			if(user!=null){
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
				TUserInfo user1 = (TUserInfo)sqlmap.queryForObject("T_USER_INFO.abatorgenerated_selectByPrimaryKey",user);
				aWebForm.setName(user1.getName());
				aWebForm.setSex(user1.getSex());
				if(user1.getBirthday()!=null){
					aWebForm.setBirthday(format.format(user1.getBirthday()));
				}else{
					aWebForm.setBirthday("");
				}

				aWebForm.setEducation(user1.getEducation());
				aWebForm.setSchoolName(user1.getSchoolName());
				aWebForm.setSpeciality(user1.getSpeciality());
				aWebForm.setMobilphone(user1.getMobilphone());
				aWebForm.setTelephone(user1.getTelephone());
				aWebForm.setNowAddress(user1.getNowAddress());
				aWebForm.setNowPostalCode(user1.getNowPostalCode());
				aWebForm.setRegisteredAddress(user1.getRegisteredAddress());
				aWebForm.setRegPostalCode(user1.getRegPostalCode());
				aWebForm.setFavoriteJob(user1.getFavoriteJob());
				aWebForm.setEducationBgDate1(user1.getEducationBgDate1());
				aWebForm.setEducationBgDate2(user1.getEducationBgDate2());
				aWebForm.setEducationBgDate3(user1.getEducationBgDate3());
				aWebForm.setEducationBg1(user1.getEducationBg1());
				aWebForm.setEducationBg2(user1.getEducationBg2());
				aWebForm.setEducationBg3(user1.getEducationBg3());
				aWebForm.setEnglish(user1.getEnglish());
				aWebForm.setSpecialityLevel(user1.getSpecialityLevel());


				aWebForm.setSocialityDate1(user1.getSocialityDate1());
				aWebForm.setSocialityDate2(user1.getSocialityDate1());
				aWebForm.setSocialityDate3(user1.getSocialityDate3());
				aWebForm.setSocialityDate2(user1.getSocialityDate2());
				aWebForm.setSocialityDate3(user1.getSocialityDate3());
				aWebForm.setSociality1(user1.getSociality1());
				aWebForm.setSociality2(user1.getSociality2());
				aWebForm.setSociality3(user1.getSociality3());
				aWebForm.setCourse(user1.getCourse());
				aWebForm.setDescriptYourself(user1.getDescriptYourself());
				aWebForm.setFeatures(user1.getFeatures());
				aWebForm.setEmail(user1.getEmail());
				if(user1.getImageURL() != null){
					aWebForm.setImageURL("/userpicture/"+user1.getImageURL());
				}else{
					aWebForm.setImageURL("/userpicture/nopicture.gif");
				}

			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 加载用户信息
	 * @param aWebForm
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public static  void  viewUserSelft(RegUserInfoForm aWebForm,HttpServletRequest request) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TUserInfo user = new TUserInfo();
		TUserInfo user2 = new TUserInfo();
		String userId = request.getParameter("userId");
		try{
			if(userId!=null && userId!=""){
				System.out.println("why:"+request.getParameter("userId"));
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
				user.setId(userId);
				TUserInfo user1 = (TUserInfo)sqlmap.queryForObject("T_USER_INFO.abatorgenerated_selectByPrimaryKey",user);
				aWebForm.setName(user1.getName());
				aWebForm.setSex(user1.getSex());
				if(user1.getBirthday()!=null){
					aWebForm.setBirthday(format.format(user1.getBirthday()));
				}else{
					aWebForm.setBirthday("");
				}

				aWebForm.setEducation(user1.getEducation());
				aWebForm.setSchoolName(user1.getSchoolName());
				aWebForm.setSpeciality(user1.getSpeciality());
				aWebForm.setMobilphone(user1.getMobilphone());
				aWebForm.setTelephone(user1.getTelephone());
				aWebForm.setNowAddress(user1.getNowAddress());
				aWebForm.setNowPostalCode(user1.getNowPostalCode());
				aWebForm.setRegisteredAddress(user1.getRegisteredAddress());
				aWebForm.setRegPostalCode(user1.getRegPostalCode());
				aWebForm.setFavoriteJob(user1.getFavoriteJob());
				aWebForm.setEducationBgDate1(user1.getEducationBgDate1());
				aWebForm.setEducationBgDate2(user1.getEducationBgDate2());
				aWebForm.setEducationBgDate3(user1.getEducationBgDate3());
				aWebForm.setEducationBg1(user1.getEducationBg1());
				aWebForm.setEducationBg2(user1.getEducationBg2());
				aWebForm.setEducationBg3(user1.getEducationBg3());
				aWebForm.setEnglish(user1.getEnglish());
				aWebForm.setSpecialityLevel(user1.getSpecialityLevel());


				aWebForm.setSocialityDate1(user1.getSocialityDate1());
				aWebForm.setSocialityDate2(user1.getSocialityDate1());
				aWebForm.setSocialityDate3(user1.getSocialityDate3());
				aWebForm.setSocialityDate2(user1.getSocialityDate2());
				aWebForm.setSocialityDate3(user1.getSocialityDate3());
				aWebForm.setSociality1(user1.getSociality1());
				aWebForm.setSociality2(user1.getSociality2());
				aWebForm.setSociality3(user1.getSociality3());
				aWebForm.setCourse(user1.getCourse());
				aWebForm.setDescriptYourself(user1.getDescriptYourself());
				aWebForm.setFeatures(user1.getFeatures());
				aWebForm.setEmail(user1.getEmail());
				if(user1.getImageURL() != null){
					aWebForm.setImageURL("/userpicture/"+user1.getImageURL());
				}else{
					aWebForm.setImageURL("/userpicture/nopicture.gif");
				}

			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	/**
	 * 浏览用户信息
	 * @param aWebForm
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public static boolean   viewUserInfo(RegUserInfoForm aWebForm,HttpServletRequest request) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TUserInfo user2 = new TUserInfo();
		boolean result = false;
		try{
			if(request.getParameter("ID").trim()!=null && request.getParameter("ID").trim()!=""){
				BaseLog.logger.info("id:"+request.getParameter("ID"));
				user2.setId(request.getParameter("ID"));

				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
				user2 = (TUserInfo)sqlmap.queryForObject("T_USER_INFO.abatorgenerated_selectByPrimaryKey",user2);
				aWebForm.setName(user2.getName());
				aWebForm.setSex(user2.getSex());
				if(user2.getBirthday()!=null){
					aWebForm.setBirthday(format.format(user2.getBirthday()));
				}else{
					aWebForm.setBirthday("");
				}
				aWebForm.setEducation(user2.getEducation());
				aWebForm.setSchoolName(user2.getSchoolName());
				aWebForm.setSpeciality(user2.getSpeciality());
				aWebForm.setMobilphone(user2.getMobilphone());
				aWebForm.setTelephone(user2.getTelephone());
				aWebForm.setNowAddress(user2.getNowAddress());
				aWebForm.setNowPostalCode(user2.getNowPostalCode());
				aWebForm.setRegisteredAddress(user2.getRegisteredAddress());
				aWebForm.setRegPostalCode(user2.getRegPostalCode());
				aWebForm.setFavoriteJob(user2.getFavoriteJob());
				aWebForm.setEducationBgDate1(user2.getEducationBgDate1());
				aWebForm.setEducationBgDate2(user2.getEducationBgDate2());
				aWebForm.setEducationBgDate3(user2.getEducationBgDate3());
				aWebForm.setEducationBg1(user2.getEducationBg1());
				aWebForm.setEducationBg2(user2.getEducationBg2());
				aWebForm.setEducationBg3(user2.getEducationBg3());
				aWebForm.setEnglish(user2.getEnglish());
				aWebForm.setSpecialityLevel(user2.getSpecialityLevel());
				aWebForm.setSocialityDate1(user2.getSocialityDate1());
				aWebForm.setSocialityDate2(user2.getSocialityDate2());
				aWebForm.setSocialityDate3(user2.getSocialityDate3());
				aWebForm.setSociality1(user2.getSociality1());
				aWebForm.setSociality2(user2.getSociality2());
				aWebForm.setSociality3(user2.getSociality3());
				aWebForm.setCourse(user2.getCourse());
				aWebForm.setDescriptYourself(user2.getDescriptYourself());
				aWebForm.setFeatures(user2.getFeatures());
				aWebForm.setEmail(user2.getEmail());
				if(user2.getImageURL() != null){
					aWebForm.setImageURL("/userpicture/"+user2.getImageURL());
				}else{
					aWebForm.setImageURL("/userpicture/nopicture.gif");
				}
				com.struts.deal.news.Deal.getHopSearchList(request);
				result=true;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}

}
